﻿package mortal.game.view.guild.otherpanel
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildAppointPanel extends GuildOtherBasePanel
    {
        private var _txtMemberName:GTextFiled;
        private var _radioBtnMaster:GRadioButton;
        private var _radioBtnDeputyMaster:GRadioButton;
        private var _radioBtnPresbyter:GRadioButton;
        private var _radioBtnLaw:GRadioButton;
        private var _radioBtnElite:GRadioButton;
        private var _radioBtnNormal:GRadioButton;
        private var _leftPostionNumTxtList:Vector.<GTextFiled>;
        private var _btnAppoint:GButton;
        private var _memberInfo:SGuildMember;
        private static var _instance:GuildAppointPanel = null;

        public function GuildAppointPanel(param1:ILayer = null)
        {
            this._leftPostionNumTxtList = new Vector.<GTextFiled>;
            super(param1);
            setSize(278, 285);
            title = "" + Language.getString(71140);
            return;
        }// end function

        override public function layoutUI() : void
        {
            var _loc_6:GTextFiled = null;
            UIFactory.gBitmap(ImagesConst.guildAppointmentBg, 12.5, 33, this);
            var _loc_1:* = GlobalStyle.textFormatJiang;
            _loc_1.size = 14;
            UIFactory.gTextField(Language.getString(60082), 63, 44, 35, 22, this, _loc_1);
            UIFactory.gTextField(Language.getString(60083) + " :", 200, 44, 35, 22, this, _loc_1);
            var _loc_2:* = GlobalStyle.textFormatJiang;
            _loc_2.size = 14;
            _loc_2.color = 4418420;
            var _loc_3:* = "<a href=\'event:memberNameLink\' target = \'\'><font color=\'#436b74\' size=\'14\'><u>" + Language.getString(71141) + "</u></font></a>";
            this._txtMemberName = UIFactory.gTextField(_loc_3, 95, 44, 105, 22, this, null, true);
            this._txtMemberName.autoSize = "center";
            var _loc_4:* = new Vector.<String>;
            _loc_4.push(Language.getString(60077), Language.getString(60078), Language.getString(60079), Language.getString(60080), Language.getString(60081), "" + Language.getString(71142));
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4.length)
            {
                
                switch(_loc_5)
                {
                    case 0:
                    {
                        this._radioBtnMaster = UIFactory.radioButton("", 70, 82 + 26 * _loc_5, 22, 22, this);
                        this._radioBtnMaster.groupName = "appointGroup";
                        break;
                    }
                    case 1:
                    {
                        this._radioBtnDeputyMaster = UIFactory.radioButton("", 70, 82 + 26 * _loc_5, 22, 22, this);
                        this._radioBtnDeputyMaster.groupName = "appointGroup";
                        break;
                    }
                    case 2:
                    {
                        this._radioBtnPresbyter = UIFactory.radioButton("", 70, 82 + 26 * _loc_5, 22, 22, this);
                        this._radioBtnPresbyter.groupName = "appointGroup";
                        break;
                    }
                    case 3:
                    {
                        this._radioBtnLaw = UIFactory.radioButton("", 70, 82 + 26 * _loc_5, 22, 22, this);
                        this._radioBtnLaw.groupName = "appointGroup";
                        break;
                    }
                    case 4:
                    {
                        this._radioBtnElite = UIFactory.radioButton("", 70, 82 + 26 * _loc_5, 22, 22, this);
                        this._radioBtnElite.groupName = "appointGroup";
                        break;
                    }
                    case 5:
                    {
                        this._radioBtnNormal = UIFactory.radioButton("", 70, 82 + 26 * _loc_5, 22, 22, this);
                        this._radioBtnNormal.groupName = "appointGroup";
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                UIFactory.gTextField(_loc_4[_loc_5], 95, 82 + 26 * _loc_5, 60, 22, this, _loc_1);
                if (_loc_5 != 0 && _loc_5 != 5)
                {
                    _loc_6 = UIFactory.gTextField("[14/15]", 145, 82 + 26 * _loc_5, 55, 22, this, _loc_2);
                    this._leftPostionNumTxtList.push(_loc_6);
                }
                _loc_5++;
            }
            this._btnAppoint = UIFactory.gButton(Language.getString(60084), 114, 255, 67, 22, this);
            return;
        }// end function

        public function setMemberData(param1:Object) : void
        {
            this._memberInfo = param1 as SGuildMember;
            this.update();
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            var positon:int;
            var guildInfo:SelfGuildInfo;
            var config:TGuildLevelTarget;
            var isFullMember:Boolean;
            var hasPermissions:Boolean;
            var isChangeLeader:Boolean;
            var changePositionCallback:Function;
            var event:* = event;
            switch(event.target)
            {
                case this._btnAppoint:
                {
                    positon;
                    guildInfo = Cache.instance.guild.selfGuildInfo;
                    config = GuildLevelTargetConfig.instance.getInfoByLevel(guildInfo.baseInfo.level);
                    isFullMember;
                    hasPermissions;
                    isChangeLeader;
                    if (this._radioBtnMaster.selected)
                    {
                        positon = EGuildPosition._EGuildLeader;
                        hasPermissions = GuildConst.hasPermissions(GuildConst.TransferPositon);
                        isChangeLeader;
                    }
                    else if (this._radioBtnDeputyMaster.selected)
                    {
                        positon = EGuildPosition._EGuildDeputyLeader;
                        hasPermissions = GuildConst.hasPermissions(GuildConst.AppointDeputyLeader);
                        isFullMember = guildInfo.deputyLeaderNum >= config.deputyLeaderAmount;
                    }
                    else if (this._radioBtnPresbyter.selected)
                    {
                        positon = EGuildPosition._EGuildPresbyter;
                        hasPermissions = GuildConst.hasPermissions(GuildConst.AppointPrestyer);
                        isFullMember = guildInfo.presbyterNum >= config.presbyterAmount;
                    }
                    else if (this._radioBtnLaw.selected)
                    {
                        positon = EGuildPosition._EGuildLaw;
                        hasPermissions = GuildConst.hasPermissions(GuildConst.AppointLaw);
                        isFullMember = guildInfo.lawNums >= config.lawAmount;
                    }
                    else if (this._radioBtnElite.selected)
                    {
                        positon = EGuildPosition._EGuildElite;
                        hasPermissions = GuildConst.hasPermissions(GuildConst.AppointElite);
                        isFullMember = guildInfo.eliteNums >= config.eliteAmount;
                    }
                    else if (this._radioBtnNormal.selected)
                    {
                        positon = EGuildPosition._EGuildMember;
                        hasPermissions = Cache.instance.guild.selfGuildInfo.selfInfo.position >= this._memberInfo.position;
                    }
                    if (positon == 0)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71143));
                        return;
                    }
                    if (this._memberInfo.position == positon)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71144));
                        return;
                    }
                    if (positon == EGuildPosition._EGuildLeader && this._memberInfo.position < EGuildPosition._EGuildDeputyLeader)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71145));
                        return;
                    }
                    if (!hasPermissions)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71146));
                        return;
                    }
                    if (isFullMember)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71147));
                        return;
                    }
                    changePositionCallback = function (param1:int) : void
            {
                var _loc_2:Object = null;
                if (param1 == Alert.OK)
                {
                    _loc_2 = new Object();
                    _loc_2.targetID = _memberInfo.miniPlayer.entityId.id;
                    _loc_2.position = positon;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_POSITION_OPRATE, _loc_2));
                    hide();
                }
                return;
            }// end function
            ;
                    if (isChangeLeader)
                    {
                        Alert.show("" + Language.getString(71148), null, Alert.OK | Alert.CANCEL, null, changePositionCallback);
                    }
                    else
                    {
                        this.changePositionCallback(Alert.OK);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function updateSelect() : void
        {
            switch(this._memberInfo.position)
            {
                case EGuildPosition._EGuildLeader:
                {
                    this._radioBtnMaster.selected = true;
                    break;
                }
                case EGuildPosition._EGuildDeputyLeader:
                {
                    this._radioBtnDeputyMaster.selected = true;
                    break;
                }
                case EGuildPosition._EGuildPresbyter:
                {
                    this._radioBtnPresbyter.selected = true;
                    break;
                }
                case EGuildPosition._EGuildLaw:
                {
                    this._radioBtnLaw.selected = true;
                    break;
                }
                case EGuildPosition._EGuildElite:
                {
                    this._radioBtnElite.selected = true;
                    break;
                }
                case EGuildPosition._EGuildMember:
                {
                    this._radioBtnNormal.selected = true;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override public function update() : void
        {
            if (!isLoadComplete)
            {
                return;
            }
            if (this._memberInfo == null)
            {
                return;
            }
            this.updateSelect();
            var _loc_1:* = "<a href=\'event:memberNameLink\' target = \'\'><font color=\'#436b74\' size=\'14\'><u>" + this._memberInfo.miniPlayer.name + "</u></font></a>";
            this._txtMemberName.htmlText = _loc_1;
            var _loc_2:* = Cache.instance.guild.selfGuildInfo;
            var _loc_3:* = this._leftPostionNumTxtList[0];
            _loc_3.text = "[" + _loc_2.deputyLeaderNum + "/" + _loc_2.getLevelConfig().deputyLeaderAmount + "]";
            var _loc_4:* = this._leftPostionNumTxtList[1];
            _loc_4.text = "[" + _loc_2.presbyterNum + "/" + _loc_2.getLevelConfig().presbyterAmount + "]";
            var _loc_5:* = this._leftPostionNumTxtList[2];
            _loc_5.text = "[" + _loc_2.lawNums + "/" + _loc_2.getLevelConfig().lawAmount + "]";
            var _loc_6:* = this._leftPostionNumTxtList[3];
            _loc_6.text = "[" + _loc_2.eliteNums + "/" + _loc_2.getLevelConfig().eliteAmount + "]";
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._leftPostionNumTxtList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : GuildAppointPanel
        {
            if (!_instance)
            {
                _instance = new GuildAppointPanel;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
